package com.climb.moive.service.impl;

import com.climb.moive.dao.MovieDao;
import com.climb.moive.dao.impl.MovieDaoImpl;
import com.climb.moive.entity.Movie;
import com.climb.moive.exception.ApplicationException;
import com.climb.moive.service.MovieService;

import java.sql.SQLException;
import java.util.List;

public class MovieServiceImpl implements MovieService {
    MovieDao movieDao=new MovieDaoImpl();

    @Override
    public Integer countMovieNum() {
        try {
            return movieDao.countMovie();
        } catch (SQLException throwables) {
            throw new ApplicationException("计算电影总数失败", throwables);
        }
    }

    @Override
    public List<Movie> findAllMovie() {
        try {
            return movieDao.findAllMovie();
        } catch (SQLException throwables) {
            throw new ApplicationException("查找所有电影失败", throwables);
        }
    }

    @Override
    public List<Movie> findMoveByDirector(String name) {
        try {
            return movieDao.findMoveByDirector(name);
        } catch (SQLException throwables) {
            throw new ApplicationException("查找所有电影失败by导演", throwables);
        }
    }

    @Override
    public List<Movie> findMoveByMovieName(String name) {
        try {
            return movieDao.findMoveByMovieName(name);
        } catch (SQLException throwables) {
            throw new ApplicationException("查找所有电影失败by电影名字", throwables);
        }
    }

    @Override
    public List<Movie> findMoveByActor(String name) {
        try {
            return movieDao.findMoveByActor(name);
        } catch (SQLException throwables) {
            throw new ApplicationException("查找所有电影失败by演员", throwables);
        }
    }

    @Override
    public List<Movie> findRecentlyReleaseMovies() {
        try {
            return movieDao.findRecentlyReleaseMovies();
        } catch (SQLException throwables) {
            throw new ApplicationException("查找最近热门电影失败", throwables);
        }
    }

    @Override
    public List<Movie> findMoviesbyType(String type) {
        try {
            return movieDao.findMoviesbyType(type);
        } catch (SQLException throwables) {
            throw new ApplicationException("查找"+type+"类型电影失败", throwables);
        }
    }

    @Override
    public List<Movie> findMoviesbyLanguage(String language) {
        try {
            return movieDao.findMoviesbyLanguage(language);
        } catch (SQLException throwables) {
            throw new ApplicationException("查找"+language+"类型电影失败", throwables);
        }
    }


    @Override
    public void insert(Movie movie) {
        try {
            movieDao.insert(movie);
        } catch (SQLException ex) {
            throw new ApplicationException("添加失败", ex);

        }
    }

    @Override
    public void update(Movie movie) {
        try {
            movieDao.update(movie);
        } catch (SQLException throwables) {
            throw new ApplicationException("修改电影信息失败",throwables);
        }
    }

    @Override
    public void delet(Integer id) {
        try {
            movieDao.delete(id);
        } catch (SQLException throwables) {
            throw new ApplicationException("删除电影失败",throwables);
        }
    }

    @Override
    public Movie findMovieById(Integer id) {
        try {
            return movieDao.findMovieById(id);
        } catch (SQLException throwables) {
            throw new ApplicationException("查找电影详情失败", throwables);
        }
    }
}
